export default {
  data() {
    return {
      ls_password:'',
      ls_username:'',
      color1:'',
      dialogTableVisible: false,
      dialogFormVisible: false,
      isCollapse:false,
      form: {
        oldpassword: '',
        newpassword: '',
        confirm_password: '',
      },
      formLabelWidth: '70px',
      PasswordFormRules: {
        // 密码的校验规则
        oldpassword: [{ required: true, message: "请输入旧密码", trigger: "blur" }],
        newpassword: [{ required: true, message: "请输入新密码", trigger: "blur" }],
        confirm_password:  [{ required: true, message: "请再次输入密码", trigger: "blur" }]
      }
    }
  },
  // 渲染天气插件
  mounted(){
    (function(T,h,i,n,k,P,a,g,e){g=function(){P=h.createElement(i);a=h.getElementsByTagName(i)[0];P.src=k;P.charset="utf-8";P.async=1;a.parentNode.insertBefore(P,a)};T["ThinkPageWeatherWidgetObject"]=n;T[n]||(T[n]=function(){(T[n].q=T[n].q||[]).push(arguments)});T[n].l=+new Date();if(T.attachEvent){T.attachEvent("onload",g)}else{T.addEventListener("load",g,false)}}(window,document,"script","tpwidget","//widget.seniverse.com/widget/chameleon.js"))
    tpwidget("init", {
      "flavor": "slim",
      "location": "WX4FBXXFKE4F",
      "geolocation": "enabled",
      "language": "zh-chs",
      "unit": "c",
      "theme": "chameleon",
      "container": "tp-weather-widget",
      "bubble": "enabled",
      "alarmType": "badge",
      "color": "#FFFFFF",
      "uid": "UF2F75BCDB",
      "hash": "3e9f47e583d4be15611b1e978781517c"
  });
  tpwidget("show");
  },
  created() {
    this.getseen()
  },
  methods: {
    // 获取登录信息
    getseen(){
      this.ls_username=sessionStorage.getItem("username");
      this.ls_password=sessionStorage.getItem("password");
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    // 更换路由
    handleselect(index) {
      this.$router.push(index)
    },
    // 打开修改密码弹窗
    handleCommand() {
      this.dialogFormVisible = true
    },
    // 点击确定修改密码
    async  determine() {
      if (this.form.newpassword !== this.form.confirm_password) return this.$message.error('两次密码不一致！');
      // 发送修改密码请求
      var url = "accounts/changepass/",
      data = {
        oldpassword: this.form.oldpassword,
        newpassword: this.form.newpassword,
        confirm_password: this.form.confirm_password
      },
      transFn = function(data) {
        return $.param(data);
      },
      postCfg = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
        },
        transformRequest: transFn
      };
    const { data: res } = await this.$http.post(url, data, postCfg);
    console.log(res)
    if (res.code !== 1) return this.$message.error(res.msg);
    this.$message.success("修改成功！");
      
    },
    // 关闭清空表单
    empty() {
      this.$refs.Modify_password.resetFields();
    },
    // 点击退出登录
    logout() {
      sessionStorage.clear()
      this.$router.push('/')
    },
    ceshicolor(){
      console.log(this.color1)
    }

  }
}
